/*     */ package com.jcrj.service;
/*     */ 
/*     */ import com.jcrj.dao.AttendenceManageDao;
/*     */ import com.jcrj.entity.OAttendGroup;
/*     */ import com.jcrj.entity.OAttendUser;
/*     */ import com.jcrj.entity.OAttendance;
/*     */ import com.jcrj.entity.OAttendanceHoliday;
/*     */ import com.jcrj.entity.OAttendanceRecord;
/*     */ import com.jcrj.entity.OAttendanceSet;
/*     */ import com.jcrj.entity.OUser;
/*     */ import com.jcrj.util.DateUtil;
/*     */ import com.jcrj.util.English;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ 
/*     */ public class AttendenceManageService
/*     */ {
/*     */   private AttendenceManageDao attendenceManageDao;
/*  24 */   Date d = new Date();
/*     */ 
/*     */   public void saveGroup(OAttendGroup attenGroup) {
/*  27 */     this.attendenceManageDao.saveText(attenGroup);
/*     */   }
/*     */ 
/*     */   public List<OAttendGroup> getGroups(int currentPage) {
/*  31 */     String hql = "from OAttendGroup order by id desc ";
/*  32 */     return this.attendenceManageDao.findByPage(hql, currentPage);
/*     */   }
/*     */ 
/*     */   public Long getGroupCount() {
/*  36 */     String hql = "select count(id) from OAttendGroup";
/*  37 */     return this.attendenceManageDao.countTotalByHql(hql);
/*     */   }
/*     */ 
/*     */   public OAttendGroup getgroup(int id) {
/*  41 */     return (OAttendGroup)this.attendenceManageDao.getObject(new OAttendGroup(), id);
/*     */   }
/*     */   public List<OUser> getgroupuse(int groupid) {
/*  44 */     String hql = "from OUser t where t.id in (select o.userId from OAttendUser o where o.groupId=" + groupid + ")";
/*  45 */     return this.attendenceManageDao.findByHql(hql);
/*     */   }
/*     */ 
/*     */   public List<OUser> getgroupuse(int groupid, int currentPage) {
/*  49 */     String hql = "from OUser t where t.id in (select o.userId from OAttendUser o where o.groupId=" + groupid + ")";
/*  50 */     return this.attendenceManageDao.findByPage(hql, currentPage);
/*     */   }
/*     */ 
/*     */   public Long getGroupuserCount(int groupid)
/*     */   {
/*  55 */     String hql = "select count(id) from OUser t where t.id in (select o.userId from OAttendUser o where o.groupId=" + groupid + ")";
/*  56 */     return this.attendenceManageDao.countTotalByHql(hql);
/*     */   }
/*     */ 
/*     */   public void addgroupuser(Integer groupId, String[] ids) {
/*  60 */     String hql = "delete from OAttendUser where groupId=" + groupId;
/*  61 */     this.attendenceManageDao.executeHql(hql);
/*  62 */     if ((ids != null) && (ids.length > 0))
/*  63 */       for (int i = 0; i < ids.length; i++) {
/*  64 */         OAttendUser oau = new OAttendUser();
/*  65 */         oau.setGroupId(groupId);
/*     */ 
/*  67 */         oau.setUserId(Integer.valueOf(Integer.parseInt(ids[i])));
/*  68 */         this.attendenceManageDao.saveText(oau);
/*     */       }
/*     */   }
/*     */ 
/*     */   public void deleteGroup(String[] ids)
/*     */   {
/*  74 */     if ((ids != null) && (ids.length > 0)) {
/*  75 */       String group = "";
/*  76 */       for (int i = 0; i < ids.length; i++) {
/*  77 */         if ("".equals(group))
/*  78 */           group = group + ids[i];
/*     */         else {
/*  80 */           group = group + "," + ids[i];
/*     */         }
/*     */       }
/*  83 */       String hql = "delete from OAttendGroup where id in(" + group + ")";
/*  84 */       this.attendenceManageDao.executeHql(hql);
/*  85 */       String hql1 = "delete from OAttendUser where groupId in (" + group + ")";
/*  86 */       this.attendenceManageDao.executeHql(hql1);
/*     */     }
/*     */   }
/*     */ 
/*     */   public void saveAttendanceTime(OAttendanceSet oas)
/*     */   {
/*  93 */     this.attendenceManageDao.saveText(oas);
/*     */   }
/*     */ 
/*     */   public List<OAttendanceSet> getAttendanceTime(int currentPage) {
/*  97 */     String hql = "from OAttendanceSet order by id";
/*  98 */     return this.attendenceManageDao.findByPage(hql, currentPage);
/*     */   }
/*     */ 
/*     */   public Long getAttendTimeCount() {
/* 102 */     String hql = " select count(id)from OAttendanceSet";
/* 103 */     return this.attendenceManageDao.countTotalByHql(hql);
/*     */   }
/*     */ 
/*     */   public List<OAttendanceSet> getAttendTime(int id) {
/* 107 */     String hql = "from OAttendanceSet where id=" + id;
/* 108 */     return this.attendenceManageDao.findByHql(hql);
/*     */   }
/*     */ 
/*     */   public void updateAttendTime(OAttendanceSet oas) {
/* 112 */     this.attendenceManageDao.ubdateText(oas);
/*     */   }
/*     */ 
/*     */   public void updateAttendStatus(OAttendanceSet oas) {
/* 116 */     String hql = "update OAttendanceSet set status=" + oas.getStatus() + "where id=" + oas.getId();
/* 117 */     this.attendenceManageDao.executeHql(hql);
/*     */   }
/*     */ 
/*     */   public void clearStatus() {
/* 121 */     String hql = "update OAttendanceSet set status=0";
/* 122 */     this.attendenceManageDao.executeHql(hql);
/*     */   }
/*     */   public void deleteAttendTime(String[] ids) {
/* 125 */     if ((ids != null) && (ids.length > 0)) {
/* 126 */       String group = "";
/* 127 */       for (int i = 0; i < ids.length; i++) {
/* 128 */         if ("".equals(group))
/* 129 */           group = group + ids[i];
/*     */         else {
/* 131 */           group = group + "," + ids[i];
/*     */         }
/*     */       }
/* 134 */       String hql = "delete from OAttendanceSet where id in(" + group + ")";
/* 135 */       this.attendenceManageDao.executeHql(hql);
/*     */     }
/*     */   }
/*     */ 
/*     */   public int monthExist(OUser ou, String nowMonth)
/*     */   {
/* 144 */     String hql = "from OAttendance  where userAccount='" + ou.getAccount() + "'and attendanceMonth='" + Integer.parseInt(nowMonth) + "'";
/* 145 */     List list = this.attendenceManageDao.findByHql(hql);
/* 146 */     if (list.size() == 0)
/*     */     {
/* 148 */       return 0;
/*     */     }
/*     */ 
/* 152 */     return ((OAttendance)list.get(0)).getId().intValue();
/*     */   }
/*     */ 
/*     */   public int dayExist(OUser ou, String nowDay, String nowMonth)
/*     */   {
/* 158 */     String field = English.sqlEnglish(nowDay);
/* 159 */     String sql = "select oar.* from O_ATTENDANCE  oa,O_ATTENDANCE_RECORD oar where oa.USER_ACCOUNT='" + ou.getAccount() + "'and oa.ATTENDANCE_MONTH='" + nowMonth + "' and oa." + field + "=oar.id";
/* 160 */     List list = this.attendenceManageDao.findBySql(sql);
/* 161 */     if (list.size() == 0)
/*     */     {
/* 163 */       return 0;
/*     */     }
/*     */ 
/* 167 */     Object[] a = (Object[])list.get(0);
/* 168 */     return Integer.parseInt(String.valueOf(a[0]));
/*     */   }
/*     */ 
/*     */   public String getBeforeDay()
/*     */   {
/* 174 */     Calendar cal = Calendar.getInstance();
/* 175 */     cal.add(5, -1);
/* 176 */     return String.valueOf(cal.get(5));
/*     */   }
/*     */ 
/*     */   public String getBeforeMonth()
/*     */   {
/* 181 */     Calendar cal = Calendar.getInstance();
/* 182 */     cal.add(5, -1);
/* 183 */     return String.valueOf(cal.get(1)) + String.valueOf(cal.get(2) + 1);
/*     */   }
/*     */ 
/*     */   public Date getBeforeDate() {
/* 187 */     Calendar cal = Calendar.getInstance();
/* 188 */     cal.add(5, -1);
/* 189 */     return cal.getTime();
/*     */   }
/*     */ 
/*     */   public boolean isNight(String nowTime) {
/* 193 */     String date = DateUtil.DateToString(this.d);
/* 194 */     String hql = "from OAttendanceSet where startTime<=to_date('" + date + " ','yyyy-mm-dd') and endTime>=to_date('" + date + "','yyyy-mm-dd ')";
/* 195 */     List list = this.attendenceManageDao.findByHql(hql);
/* 196 */     OAttendanceSet oas = (OAttendanceSet)list.get(0);
/*     */ 
/* 199 */     return (nowTime.compareTo("00:00") > 0) && (nowTime.compareTo(oas.getAmTime()) < 0);
/*     */   }
/*     */ 
/*     */   public boolean amSign(String nowTime)
/*     */   {
/* 209 */     String date = DateUtil.DateToString(this.d);
/*     */ 
/* 211 */     String hql = "from OAttendanceSet where startTime<=to_date('" + date + " ','yyyy-mm-dd') and endTime>=to_date('" + date + "','yyyy-mm-dd ')";
/* 212 */     List list = this.attendenceManageDao.findByHql(hql);
/* 213 */     OAttendanceSet oas = (OAttendanceSet)list.get(0);
/* 214 */     if (oas.getNightRest().compareTo("24:59") <= 0)
/*     */     {
/* 217 */       return (nowTime.compareTo("00:00") > 0) && (nowTime.compareTo(oas.getAmRest()) < 0);
/*     */     }
/*     */ 
/* 225 */     return (nowTime.compareTo(oas.getNightRest()) > 0) && (nowTime.compareTo(oas.getAmRest()) < 0);
/*     */   }
/*     */ 
/*     */   public boolean pmSign(String nowTime)
/*     */   {
/* 234 */     String date = DateUtil.DateToString(this.d);
/* 235 */     String hql = "from OAttendanceSet where startTime<=to_date('" + date + " ','yyyy-mm-dd') and endTime>=to_date('" + date + "','yyyy-mm-dd ')";
/* 236 */     List list = this.attendenceManageDao.findByHql(hql);
/* 237 */     OAttendanceSet oas = (OAttendanceSet)list.get(0);
/*     */ 
/* 240 */     return (nowTime.compareTo(oas.getAmRest()) > 0) && (nowTime.compareTo(oas.getPmRest()) < 0);
/*     */   }
/*     */ 
/*     */   public boolean amSignOut(String nowTime)
/*     */   {
/* 248 */     String date = DateUtil.DateToString(this.d);
/* 249 */     String hql = "from OAttendanceSet where startTime<=to_date('" + date + " ','yyyy-mm-dd') and to_date('" + date + "','yyyy-mm-dd ')<=endTime";
/* 250 */     List list = this.attendenceManageDao.findByHql(hql);
/* 251 */     OAttendanceSet oas = (OAttendanceSet)list.get(0);
/*     */ 
/* 254 */     return (nowTime.compareTo(oas.getAmTime()) > 0) && (nowTime.compareTo(oas.getPmTime()) < 0);
/*     */   }
/*     */ 
/*     */   public boolean pmSignOut(String nowTime)
/*     */   {
/* 262 */     String date = DateUtil.DateToString(this.d);
/* 263 */     String hql = "from OAttendanceSet where startTime<=to_date('" + date + " ','yyyy-mm-dd') and to_date('" + date + "','yyyy-mm-dd ')<=endTime";
/* 264 */     List list = this.attendenceManageDao.findByHql(hql);
/* 265 */     OAttendanceSet oas = (OAttendanceSet)list.get(0);
/*     */ 
/* 268 */     return (nowTime.compareTo(oas.getPmTime()) > 0) && (nowTime.compareTo(oas.getNightTime()) < 0);
/*     */   }
/*     */ 
/*     */   public void saveSign(OAttendanceRecord oar, OUser ou, String nowDay, String nowMonth)
/*     */   {
/*     */     try
/*     */     {
/* 277 */       this.attendenceManageDao.saveAttendRecord(oar);
/* 278 */       String field = English.sqlEnglish(nowDay);
/* 279 */       String sql = "insert into O_ATTENDANCE(id,USER_ACCOUNT,ATTENDANCE_MONTH," + field + ") values(ATTENDANCE_SEQ.nextval,'" + ou.getAccount() + "','" + nowMonth + "'," + oar.getId() + ")";
/* 280 */       this.attendenceManageDao.executeSql(sql);
/*     */     }
/*     */     catch (Exception e) {
/* 283 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void saveSign(OAttendanceRecord oar, Integer OAttendanceid, String nowMonth)
/*     */   {
/* 289 */     this.attendenceManageDao.saveText(oar);
/* 290 */     String nowDay = getNowDay();
/* 291 */     String field = English.sqlEnglish(nowDay);
/* 292 */     String sql = "update O_ATTENDANCE set " + field + "=" + oar.getId() + "where id=" + OAttendanceid;
/* 293 */     this.attendenceManageDao.executeSql(sql);
/*     */   }
/*     */ 
/*     */   public void updateOAttendance(OAttendance oa) {
/* 297 */     this.attendenceManageDao.ubdateText(oa);
/*     */   }
/*     */ 
/*     */   public void updateOAttendanceRecord(OAttendanceRecord oar) {
/* 301 */     this.attendenceManageDao.ubdateText(oar);
/*     */   }
/*     */ 
/*     */   public void saveOAttendanceRecord(OAttendanceRecord oar, String nowDay, String nowMonth) {
/* 305 */     this.attendenceManageDao.saveText(oar);
/*     */ 
/* 307 */     String field = English.sqlEnglish(nowDay);
/*     */ 
/* 309 */     String sql = "update O_ATTENDANCE set " + field + "=" + oar.getId() + "where ATTENDANCE_MONTH=" + nowMonth;
/* 310 */     this.attendenceManageDao.executeSql(sql);
/*     */   }
/*     */ 
/*     */   public OAttendance getOAttendance(int id)
/*     */   {
/* 315 */     String hql = "from OAttendance where id=" + id;
/* 316 */     List list = this.attendenceManageDao.findByHql(hql);
/* 317 */     return (OAttendance)list.get(0);
/*     */   }
/*     */ 
/*     */   public OAttendanceRecord getOAttendanceRecord(int id) {
/* 321 */     String hql = "from OAttendanceRecord where id=" + id;
/* 322 */     List list = this.attendenceManageDao.findByHql(hql);
/* 323 */     return (OAttendanceRecord)list.get(0);
/*     */   }
/*     */ 
/*     */   public OAttendance getOAttendance(String month) {
/* 327 */     String hql = "from OAttendance where attendanceMonth=" + month;
/* 328 */     List list = this.attendenceManageDao.findByHql(hql);
/* 329 */     return (OAttendance)list.get(0);
/*     */   }
/*     */ 
/*     */   public List<OAttendanceRecord> getAttendByMonth(Date d, String userAccount) {
/* 333 */     String year = String.valueOf(d.getYear() + 1900);
/* 334 */     String month = String.valueOf(d.getMonth() + 1);
/* 335 */     String day = String.valueOf(d.getDay());
/* 336 */     String field = English.sqlEnglish(day);
/*     */ 
/* 339 */     String sql = "select am_began_sian,am_end_sian ,pm_began_sian,pm_end_sian,night_began_sian,night_end_sian, creattime from (select oar.am_began_sian,oar.am_end_sian ,oar.pm_began_sian,oar.pm_end_sian,oar.night_began_sian,oar.night_end_sian, oar.creattime ,oa.user_account,oa.attendance_month from o_attendance oa,o_attendance_record oar where oa.one=oar.id or oa.two=oar.id or oa.three=oar.id or oa.four=oar.id or oa.five=oar.id or oa.six=oar.id or oa.seven=oar.id or oa.eight=oar.id or oa.nine=oar.id or oa.ten=oar.id or oa.eleven=oar.id or oa.twelve=oar.id or oa.thirteen=oar.id or oa.fourteen=oar.id or oa.fifteen=oar.id or oa.sixteen=oar.id or oa.seventeen=oar.id or oa.eighteen=oar.id or oa.nineteen=oar.id or oa.twenty=oar.id or oa.twenty_one=oar.id or oa.twenty_two=oar.id or oa.twenty_three=oar.id or oa.twenty_four=oar.id or oa.twenty_five=oar.id or oa.twenty_six=oar.id or oa.twenty_seven=oar.id or oa.twenty_eight=oar.id or oa.twenty_nine=oar.id or oa.thirty=oar.id or oa.thirty_one=oar.id ) where   user_account='" + userAccount + "' and attendance_month='" + year + month + "'";
/* 340 */     List list = null;
/*     */     try {
/* 342 */       list = this.attendenceManageDao.findBySql(sql);
/*     */     } catch (RuntimeException e) {
/* 344 */       e.printStackTrace();
/*     */     }
/* 346 */     return list;
/*     */   }
/*     */ 
/*     */   public String getNowYear()
/*     */   {
/* 351 */     Calendar cal = Calendar.getInstance();
/* 352 */     return String.valueOf(cal.get(1));
/*     */   }
/*     */ 
/*     */   public String getNowMonth() {
/* 356 */     Calendar cal = Calendar.getInstance();
/* 357 */     return String.valueOf(cal.get(2) + 1);
/*     */   }
/*     */ 
/*     */   public String getNowDay() {
/* 361 */     Calendar cal = Calendar.getInstance();
/* 362 */     return String.valueOf(cal.get(5));
/*     */   }
/*     */ 
/*     */   public String getNowTime() {
/* 366 */     Calendar cal = Calendar.getInstance();
/* 367 */     Date b = cal.getTime();
/* 368 */     SimpleDateFormat s = new SimpleDateFormat("HH:mm");
/* 369 */     return s.format(b);
/*     */   }
/*     */ 
/*     */   public boolean isSameDay(Date begin, Date end) {
/* 373 */     Calendar c1 = Calendar.getInstance();
/* 374 */     Calendar c2 = Calendar.getInstance();
/* 375 */     c1.setTime(begin);
/* 376 */     c2.setTime(end);
/*     */ 
/* 379 */     return (c1.get(1) == c2.get(1)) && 
/* 378 */       (c1.get(2) == c2.get(2)) && 
/* 379 */       (c1.get(5) == c2.get(5));
/*     */   }
/*     */ 
/*     */   public int getBetweenDays(Date begin, Date end) {
/* 383 */     int count = 0;
/* 384 */     Date now = null;
/* 385 */     if (!isSameDay(begin, end)) {
/* 386 */       now = addDays(begin, 1);
/* 387 */       count++;
/* 388 */       while (!isSameDay(now, end)) {
/* 389 */         count++;
/* 390 */         now = addDays(now, 1);
/*     */       }
/*     */     }
/*     */ 
/* 394 */     return count;
/*     */   }
/*     */ 
/*     */   public Date addDays(Date date, int amount) {
/* 398 */     if (date == null) {
/* 399 */       throw new IllegalArgumentException("The date must not be null");
/*     */     }
/* 401 */     Calendar c = Calendar.getInstance();
/* 402 */     c.setTime(date);
/* 403 */     c.add(5, amount);
/* 404 */     return c.getTime();
/*     */   }
/*     */ 
/*     */   public void saveHoliday(OAttendanceHoliday oattendanceHoliday) {
/* 408 */     this.attendenceManageDao.saveText(oattendanceHoliday);
/*     */   }
/*     */ 
/*     */   public List<OAttendanceHoliday> getHolidayList(String note, int currentPage) {
/* 412 */     String hql = " from OAttendanceHoliday o order by id desc";
/* 413 */     if ((note != null) && (!"".equals(note.trim()))) {
/* 414 */       hql = hql + " where o.note like '%" + note + "%'";
/*     */     }
/* 416 */     return this.attendenceManageDao.findByPage(hql, currentPage);
/*     */   }
/*     */   public List<OAttendanceHoliday> getHolidayList() {
/* 419 */     String hql = " from OAttendanceHoliday o";
/*     */ 
/* 421 */     return this.attendenceManageDao.findByHql(hql);
/*     */   }
/*     */   public Long getHolidayCount(String note) {
/* 424 */     String hql = "select count(*) from OAttendanceHoliday o";
/* 425 */     if ((note != null) && (!"".equals(note.trim()))) {
/* 426 */       hql = hql + " where o.note like '%" + note + "%'";
/*     */     }
/* 428 */     return this.attendenceManageDao.countTotalByHql(hql);
/*     */   }
/*     */ 
/*     */   public void deleteHoliday(String[] ids) {
/* 432 */     if (ids != null) {
/* 433 */       String id = "";
/* 434 */       for (int i = 0; i < ids.length; i++) {
/* 435 */         if (id == "")
/* 436 */           id = id + ids[i];
/*     */         else {
/* 438 */           id = id + "," + ids[i];
/*     */         }
/*     */       }
/*     */ 
/* 442 */       String hql = "delete from OAttendanceHoliday where id in(" + id + ")";
/* 443 */       this.attendenceManageDao.executeHql(hql);
/*     */     }
/*     */   }
/*     */ 
/*     */   public AttendenceManageDao getAttendenceManageDao()
/*     */   {
/* 454 */     return this.attendenceManageDao;
/*     */   }
/*     */ 
/*     */   public void setAttendenceManageDao(AttendenceManageDao attendenceManageDao) {
/* 458 */     this.attendenceManageDao = attendenceManageDao;
/*     */   }
/*     */ }

/* Location:           /Volumes/work/oa/WEB-INF/classes/
 * Qualified Name:     com.jcrj.service.AttendenceManageService
 * JD-Core Version:    0.6.0
 */